 <template>
	<view class="avatar">
		<image class="bg-img" :src="photo"></image>
		<view style="height: 550px;"></view>
		<view class="btn">
			<u-button type="primary" shape="circle" size="medium" :ripple="false" ripple-bg-color="#909399" @click='shoot'>拍照上传</u-button>
		</view>
		
		<view class="btn">
			<u-button type="primary" shape="circle" size="medium" :ripple="false" ripple-bg-color="#909399" @click='select'>手机相册</u-button>
		</view>
	</view>
 </template>

<script>
	//图片上传地址
	import url from '../../common/url.js'; 
	 
	export default {
		data(){
			return{
				photo: '/static/AI.jpg'
 			}
		},
		onLoad() {
			//#ifdef H5
			this.$u.toast("请先登录")
			//#endif
			
			// #ifdef MP
			if (!this.$u.utils.isLogin()) return
			// #endif
		},
		//上传图像
		methods:{
			select() {
				var _this=this;
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择 'album', 'camera'
					success: function (res) {
						uni.uploadFile({
						    url: url.uploadUrl,  //接口地址
							filePath: res.tempFilePaths[0],
							fileType:'image',
							name: 'image',  //后台对应的参数名
							
							success: (res) => {
								var data=JSON.parse(res.data)
								// console.log("data========", data)
								if(data.code==200){
									uni.$u.toast('上传成功')
									uni.navigateTo({
									  url:"/pages/seach/seach_face_list?url=" + data.data
									})
									console.log("data.data===", data.data)
								}else{
									uni.$u.toast(data.msg)
								}
							},
							fail(err){
								console.log(err,'上传失败')
							}
						});	  
					}
				});
			},
			shoot() {
				var _this=this;
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['camera'], //拍摄    'album', 'camera'
					success: function (res) {
						uni.uploadFile({
						    url: url.uploadUrl,  //接口地址
							filePath: res.tempFilePaths[0],
							fileType:'image',
							name: 'image',  //后台对应的参数名
							
							success: (res) => {
								var data=JSON.parse(res.data)
								// console.log("data========", data)
								if(data.code==200){
									uni.$u.toast('上传成功')
									uni.navigateTo({
									  url:"/pages/seach/seach_face_list?url=" + data.data
									})
									console.log("data.data===", data.data)
								}else{
									uni.$u.toast(data.msg)
								}
							},
							fail(err){
								console.log(err,'上传失败')
							}
						});	  
					}
				});
			}
		}
		
	}
</script>

<style>
	.btn{
		margin-top: 60rpx;
		margin-left: 240rpx;
	}
	.bg-img{
	    position: fixed;
	    width: 100%;
	    height: 100%;
	    top: 0;
	    left: 0;
	    z-index: -1;
	}
</style>